package job.mihayou;


import java.util.Arrays;
import java.util.Scanner;

/**
 * Author: Zhang Dongwei
 * Date: 2023/8/12 16:14
 * 参考题目：
 * https://mp.weixin.qq.com/s/rCxzfKRCK6WGBgmrzpjrrQ
 */
public class mhy1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] rest = new int[n];
        Arrays.sort(a);
        long res = 0;
        int curpw = 0;
        for (int i = 0 ; i < n ; i++) {
            int half = a[i]/2 + (a[i]%2 == 0 ? 0 : 1);
            if (curpw < half) {
                res += half-curpw;
                rest[i] = half - curpw;
            }
            curpw++;
        }
        for (int i = 0; i < n; i++) {
            if (curpw + rest[i] < a[i]) res += a[i] - (curpw + rest[i]);
        }
        System.out.println(res);
    }
}
